/*
 
Enterprise Social Network (ESN) is an open-source Java EE framework for
a social network application.

Copyright (C) 2006-07 (see CONTRIBUTORS file in project root)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

package esn.core.ejb.entity;

import java.io.*;

import javax.persistence.*;

/**
 * <p>Representation of user roles specific to JAAS.</p>
 * 
 * @author Anirban Basu
 *
 */
@Entity
public class UserRole implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String ROLE__ESN_USER = "esn_user";
	public static final String ROLE__ESN_ADMIN = "esn_admin";
	public static final String ROLE__ESN_EJB = "esn_ejb";
	
	private long id;
	private String role;
	private String roleGroup;
	private UserAuthentication userAuthentication;
	
	/**
	 * No-argument constructor, sets the roleGroup
	 * to "Roles". Refer to DatabaseServerLoginModule article on
	 * JBoss wiki.
	 * 
	 * @see <a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=DatabaseServerLoginModule">
	 * DatabaseServerLoginModule, Security on JBoss</a>
	 *
	 */
	public UserRole() {
		this.roleGroup = "Roles";
	}
	
	/**
	 * Accessor for user role.
	 * 
	 * @return
	 */
	@JoinColumn(nullable=false)
	public String getRole() {
		return role;
	}
	/**
	 * Mutator for user role.
	 * 
	 * @param role
	 */
	public void setRole(String role) {
		this.role = role;
	}
	
	/**
	 * Accessor for user authentication object.
	 * 
	 * @return
	 */
	@ManyToOne
	@JoinColumn(name="userId", nullable=false)
	public UserAuthentication getUserAuthentication() {
		return userAuthentication;
	}
	/**
	 * Mutator for user authentication object.
	 * 
	 * @param userAuthentication
	 */
	public void setUserAuthentication(UserAuthentication userAuthentication) {
		this.userAuthentication = userAuthentication;
	}
	/**
	 * Accessor for the primary key.
	 * 
	 * @return
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public long getId() {
		return id;
	}
	/**
	 * Mutator for the primary key.
	 * 
	 * @param id
	 */
	public void setId(long id) {
		this.id = id;
	}
	
	/**
	 * Accessor for role group.
	 * 
	 * @return
	 */
	@JoinColumn(nullable=false)
	public String getRoleGroup() {
		return roleGroup;
	}
	
	/**
	 * Mutator for role group.
	 * 
	 * @param roleGroup
	 */
	public void setRoleGroup(String roleGroup) {
		this.roleGroup = roleGroup;
	}
	
}
